import RequestProcess from "./RequestProcess";
import OperateArgs from "../operator/OperateArgs";
import OperatorDecorator from "../operator/OperatorDecorator";
import { RC } from "../config/RC";
import CheckIdExistOperator from "../operator/CheckUserIdExistOperator";
import GetMessageOperator from "../operator/GetMessageOperator";
class GetMessageRequestProcess extends RequestProcess {

    public args_generate(): void {
        this.args = new OperateArgs();
        this.args.setProperty("userId", this.req.body.userId);
        this.args.setProperty("boxType", this.req.body.boxType);
    }

    public operator_plan_generate(): void {
        const check_id_exist_operator = new CheckIdExistOperator(this.args);
        const get_message_operator = new GetMessageOperator(this.args);
        this.operator_plan = get_message_operator;
        this.operator_plan = new OperatorDecorator(check_id_exist_operator, get_message_operator);
    }

    public writeResult(rc: RC): Object {
        switch (rc) {
            case RC.SUCCESS:
                return {
                    code: "0000",
                    msg: "获取成功",
                    userId: this.getOperateArgs().getProperty("userId"),
                    messages: this.getOperateArgs().getProperty("messages")
                }
            case RC.USERID_NOTEXIST:
                return {
                    code: "1004",
                    msg: "用户ID不存在"
                }
            case RC.RECEIVERID_NOTEXIST:
                return {
                    code: "1002",
                    msg: "参数不合法"
                }
            case RC.INTERNAL_ERROR:
                return {
                    code: "1003",
                    msg: "服务器内部错误"
                }
            default:
                return {
                    code: "2000",
                    msg: "未知错误"
                }
        }
    }
}

export default GetMessageRequestProcess;